package edu.gdkm.controller;

import edu.gdkm.common.Result;
import edu.gdkm.controller.request.AdminPageRequest;
import edu.gdkm.controller.request.CategoryPageRequest;
import edu.gdkm.entity.Category;
import edu.gdkm.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//解决跨域问题
@CrossOrigin
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private ICategoryService categoryService;



    /**
     * 修改信息
     * @param obj
     * @return
     */
    @PutMapping("/update")
    public Result update(@RequestBody Category obj){
        categoryService.update(obj);
        return Result.success();
    }
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        categoryService.deleteById(id);
        return Result.success();
    }



    /**
     * 通过id获取用户数据 用于=>(修改,删除用户)
     * @return
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Category obj = categoryService.getById(id);
        return Result.success(obj);
    }
    /**
     * 新增用户
     * @return
     */
    @PostMapping("/save")
    public Result save(@RequestBody Category obj){

        categoryService.save(obj);
        return Result.success();
    }

    /**
     * 查询所有
     * @return
     */
    @GetMapping("/list")
    public Result list(){
        List<Category> list = categoryService.list();
        return Result.success(list);
    }

    /**
     * 分页查询 模糊查询
     * @param
     * @return
     */
    @GetMapping("/page")
    public Result page(CategoryPageRequest categoryPageRequest){
        return Result.success(categoryService.page(categoryPageRequest));
    }


}
